package game.editer.ui;

import hx.events.Event;
import hx.display.Quad;
import hx.display.InputLabel;

/**
 * 带标题的文本输入框组件
 */
class TitleTextInput extends BaseAttributeInput implements IAttributeInput {
	public var input:InputLabel;

	override function onInit() {
		super.onInit();

		// 输入功能
		input = new InputLabel();
		this.addChild(input);
		input.width = 120;
		input.height = 26;
		input.data = "";
		input.textFormat = Config.COMMON_INPUT_TEXT_FORMAT;
		input.background = new Quad(115, 26, 0x3e3e3e);
		input.background.x = -2;
		input.background.y = 0;
		input.label.verticalAlign = MIDDLE;
		input.addEventListener(Event.CHANGE, (e) -> {
			if (onAttributeChange != null)
				this.onAttributeChange(this);
		});
	}

	override function set_value(value:Dynamic):Dynamic {
		input.data = value;
		return super.set_value(value);
	}

	override function get_value():Dynamic {
		return input.data;
	}

	override function set_mouseEnabled(value:Bool):Bool {
		if (value) {
			input.background = new Quad(115, 26, 0x3e3e3e);
			input.background.x = -2;
			input.background.y = 0;
		} else {
			input.background = null;
		}
		return super.set_mouseEnabled(value);
	}
}
